﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using DataAccess;

namespace BusinessLogic
{
    public static class SelectChiTietGiaoDichKhachHang 
    {
       public static Entities.KhachHang tem;
        public static Entities.HDBanLe[] HDBanLe(string makho)
        {
            ArrayList array = new ArrayList();
            Entities.HDBanLe[] temp = BusinessLogic.HDBanLe.Select();
            foreach (Entities.HDBanLe item in temp)
            {
                if (item.Deleted == false && item.MaKho == makho && tem.MaKhachHang == item.MaKhachHang)
                    array.Add(item);
            }
            Entities.HDBanLe[] hdbanle = (Entities.HDBanLe[])array.ToArray(typeof(Entities.HDBanLe));
            if (hdbanle == null)
                hdbanle = new Entities.HDBanLe[0];
            return hdbanle;
        }

        public static Entities.HDBanBuon[] HDBanBuon(string makho)
        {
            ArrayList array = new ArrayList();
            Entities.HDBanBuon[] temp = BusinessLogic.HDBanBuon.Select();
            foreach (Entities.HDBanBuon item in temp)
            {
                if (item.Deleted == false && item.MaKho == makho && tem.MaKhachHang == item.MaKhachHang)
                    array.Add(item);
            }
            Entities.HDBanBuon[] hdbanbuon = (Entities.HDBanBuon[])array.ToArray(typeof(Entities.HDBanBuon));
            if (hdbanbuon == null)
                hdbanbuon = new Entities.HDBanBuon[0];
            return hdbanbuon;
        }

        public static Entities.KhachHangTraLaiBanBuon[] KHTLBB(string makho)
        {
            ArrayList array = new ArrayList();
            Entities.KhachHangTraLaiBanBuon temp = new Entities.KhachHangTraLaiBanBuon();
            temp.HanhDong = "0";
            temp.MaKho = makho;
            Entities.KhachHangTraLaiBanBuon[] temp1 =  BusinessLogic.KhachHangTraLaiBanBuon.SelectKhachHangTraLaiBanBuon(temp);
            foreach (Entities.KhachHangTraLaiBanBuon item in temp1)
            {
                if (tem.MaKhachHang == item.MaKhachHang)
                    array.Add(item);
            }
            temp1 = (Entities.KhachHangTraLaiBanBuon[])array.ToArray(typeof(Entities.KhachHangTraLaiBanBuon));
            if (temp1 == null)
                temp1 = new Entities.KhachHangTraLaiBanBuon[0];
            return temp1;
        }

        public static Entities.KhachHangTraLaiBanLe[] KHTLBL(string makho)
        {
            ArrayList array = new ArrayList();
            Entities.KhachHangTraLaiBanLe temp = new Entities.KhachHangTraLaiBanLe();
            temp.HanhDong = "0";
            temp.MaKho = makho;
            Entities.KhachHangTraLaiBanLe[] temp1 =  BusinessLogic.KhachHangTraLaiBanLe.SelectKhachHangTraLaiBanLe(temp);
            foreach (Entities.KhachHangTraLaiBanLe item in temp1)
            {
                if (tem.MaKhachHang == item.MaKhachHang)
                    array.Add(item);
            }
            temp1 = (Entities.KhachHangTraLaiBanLe[])array.ToArray(typeof(Entities.KhachHangTraLaiBanLe));
            if (temp1 == null)
                temp1 = new Entities.KhachHangTraLaiBanLe[0];
            return temp1;
        }

       public static Entities.PhieuTTCuaKH[] PhieuTTCuaKH()
        {
            ArrayList array = new ArrayList();
            Entities.PhieuTTCuaKH[] temp =  BusinessLogic.PhieuTTKH.Select();
            if (temp == null)
                return new Entities.PhieuTTCuaKH[0];
            foreach (Entities.PhieuTTCuaKH item in temp)
            {
                if (item.Deleted == false && tem.MaKhachHang == item.MaKhachHang)
                    array.Add(item);
            }
            Entities.PhieuTTCuaKH[] hdbanbuon = (Entities.PhieuTTCuaKH[])array.ToArray(typeof(Entities.PhieuTTCuaKH));
            if (hdbanbuon == null)
                hdbanbuon = new Entities.PhieuTTCuaKH[0];
            return hdbanbuon;
        }
        
        // Selct khách hàng
        public static Entities.SelectChiTietGiaoDichKhachHang Select(Entities.KhachHang tem, string makho)
        {
            try
            {
                tem = tem;
                Entities.SelectChiTietGiaoDichKhachHang temp = new Entities.SelectChiTietGiaoDichKhachHang();
                temp.HDBanBuon = HDBanBuon(makho);
                temp.HDBanLe = HDBanLe(makho);
                temp.KhachHangTraLaiBanBuon = KHTLBB(makho);
                temp.KhachHangTraLaiBanLe = KHTLBL(makho);
                temp.PhieuTTCuaKH = PhieuTTCuaKH();
                return temp;
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); return new Entities.SelectChiTietGiaoDichKhachHang(); }
            finally
            {
            }

        }
    }
}
